package com.example.demo.juc;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.stream.Stream;

/**
 * BlockingQueue
 * javaUtil.Concurrent.BlockingQueue接口有一下阻塞的实现
 * Fifo队列,LinkedBlockongqUEU,ArrayBlokingQueue(固定长度)
 * 优先级队列:Pro
 */
public class ProducerConsumer {
    private static BlockingQueue<String> queue = new ArrayBlockingQueue<>(5);

    private  static  class  Producer extends  Thread{

        @Override
        public void run() {
            try {
                queue.put("product");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("product...");
        }
    }

    private  static  class  Consumer extends  Thread{
        @Override
        public void run() {
            try {
                String product = queue.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("consume....   ");
        }
    }
}
